<template>
	<div style="width: 100%;height: 100%;-webkit-overflow-scrolling:touch;">
		<round-stores :storeList = "storeList"></round-stores>
	</div>
</template>

<script>
	import RoundStores from "../../components/RoundStore";
    import axios from 'axios';
    import { CHANGE_NAVIGATION } from '../../config/postMessage-types';
    
	export default {
		props:{
			
		},
		data(){
			return {
				stores:[],
			}
		},
		computed:{
			storeList(){
				return this.stores;
			}
		},
		components:{
			"RoundStores": RoundStores
		},
		methods:{
            checkStoreOpen(storeCode){
                return new Promise((resolve, reject) => {
                    let params = {
                        storeCode:storeCode,
                        enterpriseCode:window.api.enterprisecode
                    }
                    let config = {
                        url: window.api.base_host+'/baseStore/getStore',
                        method: 'POST',
                        data:params
                    }
                    axios(config).then((res) => {
                        let data = res.data.data[0][0];
                        resolve(data);
                    }).catch((err) => {
                        reject();
                    })
                })
            },
			getStores(){
//				var url = window.api.base_host + "/baseStore/getStoreList"
				var url = window.api.base_host + "/baseStore/getRestStore"
				var params = {
					enterprisecode:window.api.enterprisecode
				}
				var config = {
					url:url,
					methods:"GET",
					params,
//					headers:{sessionId:localStorage.getItem('sessionId')}
				}
				axios(config).then(async (res)=>{
//					console.log(res.data.data);
//					console.log(res.data.returnCode)
                    console.log(res,'请求门店信息')
					if(res.data.returnCode == 1){
                        let arr = res.data.data[0];
                        let arrHaveAddress = [];
                        let arrNoAddress = [];
                        for(let i = 0; i < arr.length;i++){
                            let obj = await this.checkStoreOpen(arr[i].storeCode);
                            // console.log(obj,'async')
                            // businessGoodsIsOpen === 1 并且 status === 0门店才是开启状态
                            if(obj.businessGoodsIsOpen === 1 && obj.status === 0){
                                if(arr[i].positionLat && arr[i].positionLng){
                                    arrHaveAddress.push(arr[i]);
                                }else{
                                    arrNoAddress.push(arr[i]);
                                }
                            }
                        }
						this.stores = arrHaveAddress.concat(arrNoAddress);
					}
				})
			}
		},
		created() {
            let titleConfig = JSON.stringify({
                type: CHANGE_NAVIGATION,
                params: {
                    title: "周边门店"
                }
            })
            setTimeout(() => {
                window.postMessage(titleConfig)
            },300)
			this.getStores();
        },
        mounted() {
            
        },
        updated() {
            
        },
        watch: {
           
        }
	}
</script>

<style scoped="scoped">
	
</style>